package ca.inrs.ete.app.shopx;

import android.content.SharedPreferences;

public class SHOPPreferences {
	private int dataBufferSize;
	private SHOPFoldersViewAdapter.VIEW_MODE filesMode;
	private SHOPFilesViewAdapter.VIEW_MODE   imageMode;

	public SHOPPreferences(){
		dataBufferSize = 3;
		filesMode = SHOPFoldersViewAdapter.VIEW_MODE.VIEW_MODE_GRID;
		imageMode = SHOPFilesViewAdapter.VIEW_MODE.VIEW_MODE_PAGER;
	}


	/**
	 * @return the dataBufferSize
	 */
	public int getDataBufferSize() {
		return dataBufferSize;
	}

	/**
	 * @return the filesMode
	 */
	public SHOPFoldersViewAdapter.VIEW_MODE getFilesMode() {
		return filesMode;
	}

	/**
	 * @return the imageMode
	 */
	public SHOPFilesViewAdapter.VIEW_MODE getImageMode() {
		return imageMode;
	}

	public void readValues(SharedPreferences settings){
		String buf;
		buf = settings.getString("pref_main_data_buffer_size", "3");
		dataBufferSize = Integer.parseInt(buf);
		buf = settings.getString("pref_main_files_view_mode", filesMode.toString());
		filesMode = SHOPFoldersViewAdapter.VIEW_MODE.valueOf(buf);		
		buf = settings.getString("pref_main_image_view_mode", imageMode.toString());
		imageMode = SHOPFilesViewAdapter.VIEW_MODE.valueOf(buf);		
	}

	public void writeValues(SharedPreferences settings){
		SharedPreferences.Editor editor = settings.edit();

		editor.putString("pref_main_data_buffer_size",String.format("%d", dataBufferSize));
		editor.putString("pref_main_files_view_mode", String.format("%d", filesMode.toString()));
		editor.putString("pref_main_image_view_mode", String.format("%d", imageMode.toString()));
		
		editor.commit();
	}

}
